from app.dos.user_do import userRegisterDo
from app.entitys.user_entity import UserRegisterEntity
from app.exception_handlers.CustomExceptionHandler import CreateUserException
from app.models.usermodel import User


class UserDao:
    """
    用户数据访问对象
    """
    @staticmethod
    async def create_user_by_username_password(urd:userRegisterDo):
        """
        通过用户名和密码创建用户
        :param urd:
        :return:
        """
        try:
            user = await User().create(username=urd.username, password=urd.password)
            return UserRegisterEntity.model_validate(user,from_attributes=True)
        except Exception as e:
            raise CreateUserException(username=urd.username, err_msg=str(e))
